package com.lightsh.widget.testactivity;

import com.lightsh.widget.R;
import com.lightsh.widget.Rotate3dLayout;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.FrameLayout.LayoutParams;

public class Rotate3dActivity extends Activity implements OnClickListener{
	
	private Rotate3dLayout mRotateLayout;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.rotate3d_layout);
//        mRotateLayout = (Rotate3dLayout)findViewById(R.id.rotateLayout);
        
        mRotateLayout = new Rotate3dLayout(this);
        
        mRotateLayout.setDepthZ(600f);
        mRotateLayout.setInterpolator(new AccelerateInterpolator(1.5f), new DecelerateInterpolator(1.5f));
        
        LayoutParams frameParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        
        ImageView image1 = new ImageView(this);
        image1.setLayoutParams(frameParams);
        image1.setImageResource(R.drawable.bitmap1);
        image1.setId(R.id.image1);
        
        ListView listView = new ListView(this);
        listView.setLayoutParams(frameParams);
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, "a b c".split(" ")));
        listView.setVisibility(View.GONE);
        
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				mRotateLayout.startRotate(0, false);
				
			}
		});
        
        mRotateLayout.addView(image1);
        mRotateLayout.addView(listView);
        
        
        setContentView(mRotateLayout);
        
        findViewById(R.id.image1).setOnClickListener(this);
        //findViewById(R.id.image2).setOnClickListener(this);
        
        
    }
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.image1:{
			mRotateLayout.startRotate(1, true);
		}
			break;
		case R.id.image2:{
			mRotateLayout.startRotate(0, false);
		}
			break;
		}
		
	}
}
